import React from 'react'
import store from '../../redux/store'
import {increAction, decreAction, asyncIncreAction} from '../../redux/reducers/countReducer';
import { jiaAction, jianAction } from '../../redux/reducers/zanReducer';
export default function Redux() {
  //声明函数
  let add = () => {
    store.dispatch(increAction(1));
  }

  //点击减 按钮
  let minus = () => {
    store.dispatch(decreAction(1));
  }

  //异步增加
  let asyncAdd = () => {
    store.dispatch(asyncIncreAction(10));
  }
  //获取 redux 中保存的数据
  let {count,zan} = store.getState()
  return (
    <div style={{padding: '50px'}}>
      <h2>当前的状态值: {count}</h2>
      <hr />
      <button onClick={add}> +1 </button>
      <button onClick={minus}> -1 </button>
      <button onClick={asyncAdd}>1 秒后增加 10</button>

      <hr />
      <h2>当前的点赞数: {zan}</h2>
      <button onClick={() => {
        store.dispatch(jiaAction(1));
      }}>+1</button>
      <button onClick={() => {
        store.dispatch(jianAction(1));
      }}>-1</button>
    </div>
  )
}
